﻿using System;
using System.ComponentModel;
using System.Runtime.InteropServices;

namespace Teigha.Core
{
	public class OdSiSpatialIndex : OdRxObject
	{
		[EditorBrowsable(EditorBrowsableState.Never)]
		public OdSiSpatialIndex(IntPtr cPtr, bool cMemoryOwn) : base(GlobalsPINVOKE.OdSiSpatialIndex_SWIGUpcast(cPtr), cMemoryOwn)
		{
			this.swigCPtr = new HandleRef(this, cPtr);
		}

		[EditorBrowsable(EditorBrowsableState.Never)]
		public static HandleRef getCPtr(OdSiSpatialIndex obj)
		{
			if (obj != null)
			{
				return obj.swigCPtr;
			}
			return new HandleRef(null, IntPtr.Zero);
		}

		~OdSiSpatialIndex()
		{
			this.Dispose();
		}

		public override void Dispose()
		{
			if (this.swigCPtr.Handle != IntPtr.Zero)
			{
				if (this.swigCMemOwn)
				{
					lock (this.locker)
					{
						if (this.swigCPtr.Handle != IntPtr.Zero && this.swigCMemOwn)
						{
							this.swigCMemOwn = false;
							GlobalsPINVOKE.delete_OdSiSpatialIndex(this.swigCPtr);
						}
					}
					this.swigCMemOwn = false;
				}
				this.swigCPtr = new HandleRef(null, IntPtr.Zero);
			}
			GC.SuppressFinalize(this);
			base.Dispose();
		}

		public new static OdSiSpatialIndex cast(OdRxObject pObj)
		{
			MemoryManager memoryManager = MemoryManager.GetMemoryManager();
			MemoryTransaction currentTransaction = memoryManager.GetCurrentTransaction();
			IntPtr p = GlobalsPINVOKE.OdSiSpatialIndex_cast(OdRxObject.getCPtr(pObj));
			OdSiSpatialIndex result;
			if (currentTransaction != null)
			{
				currentTransaction.AddObject((OdSiSpatialIndex)Teigha.Core.Helpers.odrxCreateObjectInternal(p, true));
				result = (OdSiSpatialIndex)Teigha.Core.Helpers.odrxCreateObjectInternal(p, false);
			}
			else
			{
				result = (OdSiSpatialIndex)Teigha.Core.Helpers.odrxCreateObjectInternal(p, true);
			}
			if (GlobalsPINVOKE.SWIGPendingException.Pending)
			{
				throw GlobalsPINVOKE.SWIGPendingException.Retrieve();
			}
			return result;
		}

		public new static OdRxClass desc()
		{
			OdRxClass result = (OdRxClass)Teigha.Core.Helpers.odrxCreateObjectInternal(GlobalsPINVOKE.OdSiSpatialIndex_desc(), false);
			if (GlobalsPINVOKE.SWIGPendingException.Pending)
			{
				throw GlobalsPINVOKE.SWIGPendingException.Retrieve();
			}
			return result;
		}

		public new virtual OdRxClass isA()
		{
			OdRxClass result = (OdRxClass)Teigha.Core.Helpers.odrxCreateObjectInternal(GlobalsPINVOKE.OdSiSpatialIndex_isA(this.swigCPtr), false);
			if (GlobalsPINVOKE.SWIGPendingException.Pending)
			{
				throw GlobalsPINVOKE.SWIGPendingException.Retrieve();
			}
			return result;
		}

		public new virtual OdRxObject queryX(OdRxClass protocolClass)
		{
			OdRxObject result = Teigha.Core.Helpers.odrxCreateObjectInternal(GlobalsPINVOKE.OdSiSpatialIndex_queryX(this.swigCPtr, OdRxClass.getCPtr(protocolClass)), false);
			if (GlobalsPINVOKE.SWIGPendingException.Pending)
			{
				throw GlobalsPINVOKE.SWIGPendingException.Retrieve();
			}
			return result;
		}

		public static OdSiSpatialIndex createObject()
		{
			MemoryManager memoryManager = MemoryManager.GetMemoryManager();
			MemoryTransaction currentTransaction = memoryManager.GetCurrentTransaction();
			IntPtr p = GlobalsPINVOKE.OdSiSpatialIndex_createObject__SWIG_0();
			OdSiSpatialIndex result;
			if (currentTransaction != null)
			{
				currentTransaction.AddObject((OdSiSpatialIndex)Teigha.Core.Helpers.odrxCreateObjectInternal(p, true));
				result = (OdSiSpatialIndex)Teigha.Core.Helpers.odrxCreateObjectInternal(p, false);
			}
			else
			{
				result = (OdSiSpatialIndex)Teigha.Core.Helpers.odrxCreateObjectInternal(p, true);
			}
			if (GlobalsPINVOKE.SWIGPendingException.Pending)
			{
				throw GlobalsPINVOKE.SWIGPendingException.Retrieve();
			}
			return result;
		}

		public static OdSiSpatialIndex createObject(uint flags, uint initialNumEntity, uint maxDepth, uint maxCount, double eps)
		{
			MemoryManager memoryManager = MemoryManager.GetMemoryManager();
			MemoryTransaction currentTransaction = memoryManager.GetCurrentTransaction();
			IntPtr p = GlobalsPINVOKE.OdSiSpatialIndex_createObject__SWIG_1(flags, initialNumEntity, maxDepth, maxCount, eps);
			OdSiSpatialIndex result;
			if (currentTransaction != null)
			{
				currentTransaction.AddObject((OdSiSpatialIndex)Teigha.Core.Helpers.odrxCreateObjectInternal(p, true));
				result = (OdSiSpatialIndex)Teigha.Core.Helpers.odrxCreateObjectInternal(p, false);
			}
			else
			{
				result = (OdSiSpatialIndex)Teigha.Core.Helpers.odrxCreateObjectInternal(p, true);
			}
			if (GlobalsPINVOKE.SWIGPendingException.Pending)
			{
				throw GlobalsPINVOKE.SWIGPendingException.Retrieve();
			}
			return result;
		}

		public static OdSiSpatialIndex createObject(uint flags, uint initialNumEntity, uint maxDepth, uint maxCount)
		{
			MemoryManager memoryManager = MemoryManager.GetMemoryManager();
			MemoryTransaction currentTransaction = memoryManager.GetCurrentTransaction();
			IntPtr p = GlobalsPINVOKE.OdSiSpatialIndex_createObject__SWIG_2(flags, initialNumEntity, maxDepth, maxCount);
			OdSiSpatialIndex result;
			if (currentTransaction != null)
			{
				currentTransaction.AddObject((OdSiSpatialIndex)Teigha.Core.Helpers.odrxCreateObjectInternal(p, true));
				result = (OdSiSpatialIndex)Teigha.Core.Helpers.odrxCreateObjectInternal(p, false);
			}
			else
			{
				result = (OdSiSpatialIndex)Teigha.Core.Helpers.odrxCreateObjectInternal(p, true);
			}
			if (GlobalsPINVOKE.SWIGPendingException.Pending)
			{
				throw GlobalsPINVOKE.SWIGPendingException.Retrieve();
			}
			return result;
		}

		public static OdSiSpatialIndex createObject(uint flags, uint initialNumEntity, uint maxDepth)
		{
			MemoryManager memoryManager = MemoryManager.GetMemoryManager();
			MemoryTransaction currentTransaction = memoryManager.GetCurrentTransaction();
			IntPtr p = GlobalsPINVOKE.OdSiSpatialIndex_createObject__SWIG_3(flags, initialNumEntity, maxDepth);
			OdSiSpatialIndex result;
			if (currentTransaction != null)
			{
				currentTransaction.AddObject((OdSiSpatialIndex)Teigha.Core.Helpers.odrxCreateObjectInternal(p, true));
				result = (OdSiSpatialIndex)Teigha.Core.Helpers.odrxCreateObjectInternal(p, false);
			}
			else
			{
				result = (OdSiSpatialIndex)Teigha.Core.Helpers.odrxCreateObjectInternal(p, true);
			}
			if (GlobalsPINVOKE.SWIGPendingException.Pending)
			{
				throw GlobalsPINVOKE.SWIGPendingException.Retrieve();
			}
			return result;
		}

		public static OdSiSpatialIndex createObject(uint flags, uint initialNumEntity)
		{
			MemoryManager memoryManager = MemoryManager.GetMemoryManager();
			MemoryTransaction currentTransaction = memoryManager.GetCurrentTransaction();
			IntPtr p = GlobalsPINVOKE.OdSiSpatialIndex_createObject__SWIG_4(flags, initialNumEntity);
			OdSiSpatialIndex result;
			if (currentTransaction != null)
			{
				currentTransaction.AddObject((OdSiSpatialIndex)Teigha.Core.Helpers.odrxCreateObjectInternal(p, true));
				result = (OdSiSpatialIndex)Teigha.Core.Helpers.odrxCreateObjectInternal(p, false);
			}
			else
			{
				result = (OdSiSpatialIndex)Teigha.Core.Helpers.odrxCreateObjectInternal(p, true);
			}
			if (GlobalsPINVOKE.SWIGPendingException.Pending)
			{
				throw GlobalsPINVOKE.SWIGPendingException.Retrieve();
			}
			return result;
		}

		public virtual void insert(OdSiEntity entity)
		{
			GlobalsPINVOKE.OdSiSpatialIndex_insert(this.swigCPtr, entity.GetCPtr());
			if (GlobalsPINVOKE.SWIGPendingException.Pending)
			{
				throw GlobalsPINVOKE.SWIGPendingException.Retrieve();
			}
		}

		public virtual bool remove(OdSiEntity entity)
		{
			bool result = GlobalsPINVOKE.OdSiSpatialIndex_remove(this.swigCPtr, entity.GetCPtr());
			if (GlobalsPINVOKE.SWIGPendingException.Pending)
			{
				throw GlobalsPINVOKE.SWIGPendingException.Retrieve();
			}
			return result;
		}

		public virtual void query(OdSiShape shape, OdSiVisitor visitor)
		{
			GlobalsPINVOKE.OdSiSpatialIndex_query(this.swigCPtr, shape.GetCPtr(), OdSiVisitor.getCPtr(visitor));
			if (GlobalsPINVOKE.SWIGPendingException.Pending)
			{
				throw GlobalsPINVOKE.SWIGPendingException.Retrieve();
			}
		}

		public virtual void clear()
		{
			GlobalsPINVOKE.OdSiSpatialIndex_clear(this.swigCPtr);
			if (GlobalsPINVOKE.SWIGPendingException.Pending)
			{
				throw GlobalsPINVOKE.SWIGPendingException.Retrieve();
			}
		}

		public virtual void setMaxTreeDepth(byte maxDepth)
		{
			GlobalsPINVOKE.OdSiSpatialIndex_setMaxTreeDepth(this.swigCPtr, maxDepth);
			if (GlobalsPINVOKE.SWIGPendingException.Pending)
			{
				throw GlobalsPINVOKE.SWIGPendingException.Retrieve();
			}
		}

		public virtual void setMaxNodeSize(byte maxCount)
		{
			GlobalsPINVOKE.OdSiSpatialIndex_setMaxNodeSize(this.swigCPtr, maxCount);
			if (GlobalsPINVOKE.SWIGPendingException.Pending)
			{
				throw GlobalsPINVOKE.SWIGPendingException.Retrieve();
			}
		}

		public virtual bool extents(OdGeExtents3d extents)
		{
			bool result = GlobalsPINVOKE.OdSiSpatialIndex_extents(this.swigCPtr, OdGeExtents3d.getCPtr(extents));
			if (GlobalsPINVOKE.SWIGPendingException.Pending)
			{
				throw GlobalsPINVOKE.SWIGPendingException.Retrieve();
			}
			return result;
		}

		public virtual uint maxTreeDepth()
		{
			uint result = GlobalsPINVOKE.OdSiSpatialIndex_maxTreeDepth(this.swigCPtr);
			if (GlobalsPINVOKE.SWIGPendingException.Pending)
			{
				throw GlobalsPINVOKE.SWIGPendingException.Retrieve();
			}
			return result;
		}

		public virtual uint maxNodeSize()
		{
			uint result = GlobalsPINVOKE.OdSiSpatialIndex_maxNodeSize(this.swigCPtr);
			if (GlobalsPINVOKE.SWIGPendingException.Pending)
			{
				throw GlobalsPINVOKE.SWIGPendingException.Retrieve();
			}
			return result;
		}

		public virtual OdGeTol tolerance()
		{
			OdGeTol result = new OdGeTol(GlobalsPINVOKE.OdSiSpatialIndex_tolerance(this.swigCPtr), false);
			if (GlobalsPINVOKE.SWIGPendingException.Pending)
			{
				throw GlobalsPINVOKE.SWIGPendingException.Retrieve();
			}
			return result;
		}

		private object locker = new object();

		private HandleRef swigCPtr;

		public enum CreationFlags
		{
			kSiNoFlags,
			kSiPlanar,
			kSiModifyMtAware,
			kSiAccessMtAware = 4,
			kSiFullMtAware = 6
		}
	}
}
